import React, { useEffect } from "react";
import UserList from "../components/user/List";
import { connect } from "dva";

function UserPage({ userList, dispatch }) {
  useEffect(() => {

    dispatch({
      type:"userInfo/asyncInitList",
      payload:{}
    })
    // userQuery({}).then((res) => {
    //   dispatch({
    //     type: "userInfo/initList",
    //     payload: res.data,
    //   });

   // });
    // setTimeout(() => {
    //   dispatch({
    //     type: "userInfo/initList",
    //     payload: [
    //       { id: 1, username: "leson", userage: 18 },
    //       { id: 2, username: "lulu", userage: 18 },
    //     ],
    //   });
    //  }, 1000);

    // return () => {};
  }, []);
  let onDelete = async (payload) => {
   // await  userDel(payload);
    dispatch({
      type: "userInfo/asyncDelById",
      payload,
    });
  };

  return (
    <div>
      <UserList list={userList} onDelete={onDelete}></UserList>
    </div>
  );
}
let mapStateToProps = ({ userInfo }) => ({ userList: userInfo });

export default connect(mapStateToProps)(UserPage);
